﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VAdvantage.Classes;
using VAdvantage.Common;
//using ViennaAdvantage.Process;
//using System.Windows.Forms;
//using ViennaAdvantage.Model;
using VAdvantage.DataBase;
using VAdvantage.SqlExec;
using VAdvantage.Utility;
using System.Data;
using VAdvantage.Logging;
//using VAdvantage.Controller;
using VAdvantage.Model;
using VAdvantage.Grids;
using System.Windows;

namespace VAdvantage.Model
{
    public class CalloutPriceListOpp : VAdvantage.Model.CalloutEngine
    {
        public String PriceList(Context ctx, int WindowNo, GridTab mTab, GridField mField, Object value)
        {
            if (value == DBNull.Value || value == null || value.ToString() == "")
            {
                return "";
            }
            String sql = "";
            try
            {
                sql = "select M_PriceList_ID from M_PriceList_Version where M_PriceList_Version_ID = " + Util.GetValueOfInt(value);
                int M_PriceList_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null));
                if (M_PriceList_ID != 0)
                {
                    mTab.SetValue("M_PriceList_ID", M_PriceList_ID);

                    sql = "select C_Currency_id from m_pricelist where m_pricelist_ID = " + M_PriceList_ID;
                    int C_Currency_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null));
                    if (C_Currency_ID != 0)
                    {
                        mTab.SetValue("C_Currency_ID", C_Currency_ID);
                    }
                    else
                    {
                        ShowMessage.Info("CurrencyNotDefinedForThePriceList", true, null, null);
                    }
                }

            }
            catch
            {
                log.SaveError(sql, sql);
            }
            return "";
        }
    }
}
